<?php
/**
 * Created by PhpStorm.
 * User: lijie
 * Date: 2018/10/13
 * Time: 9:17
 */
namespace app\reserve\model;

use think\Model;

class Adminaction extends Model{

    protected $table = "orange_admin_action";
    protected $autoWriteTimestamp = true;
    protected $createTime = "ctime";
    protected $updateTime = "utime";
    protected $dateFormat;
    protected $insert = ['status'=>0];

    /**
     * 添加权限
     * User: lijie
     * Date: 2018/10/13
     */
    public function addAction($data)
    {
        return $this->isUpdate(false)->allowField(true)->save($data);
    }

    /**
     * 删除权限
     * User: lijie
     * Date: 2018/10/13
     */
    public function delAction($data)
    {
        return $this->isUpdate(true)->save(['status'=>9],['action_id'=>$data]);
    }

    /**
     * 编辑权限
     * User: lijie
     * Date: 2018/10/13
     */
    public function editAction($data,$where)
    {
        unset($data['action_id']);
        return $this->isUpdate(true)->allowField(true)->save($data,$where);
    }

    /**
     * 权限列表二级分类
     * User: lijie
     * Date: 2018/10/13
     */
    public function selectAction($where)
    {
        $re  = $this->where($where)->field("action_id as id,action_name as label")->select();
        return $re;
    }

    /**
     * 权限列表
     * User: lijie
     * Date: 2018/10/15
     */
    public function actionList($where,$pagenum,$listNum)
    {
        $res = $this->where($where)->order("ctime desc")->page($pagenum,$listNum)->field("action_id,fid,action_name,action_name_en,ctime,utime,status")->select();
        return $res;
    }

    /**
     * 权限详情
     * User: lijie
     * Date: 2018/10/13
     */
    public function findAction($where)
    {
        return $this->where($where)->field("action_id,fid,action_name,action_name_en,ctime,utime,status")->find();
    }
}